package xiaomi;

import java.util.Scanner;

/**
 * @author xizizzz
 * @description: TODO
 * @date 2021-9-1下午 07:25
 */
public class Test1 {
    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        final String[] split = sc.nextLine().split(",");
        int m = Integer.parseInt(split[0].substring(2));
        int n = Integer.parseInt(split[1].substring(2));
        final String[] split1 = sc.nextLine().split(",");
        int[] num1 = new int[m + n];
        for (int i = 0; i < split1.length; i++) {
            num1[i] = Integer.parseInt(split1[i]);
        }
        int[] num2 = new int[n];
        final String[] split2 = sc.nextLine().split(",");
        for (int i = 0; i < split2.length; i++) {
            num2[i] = Integer.parseInt(split2[i]);
        }
        final int[] merge = merge(num1, m, num2, n);
        for (int i = 0; i < merge.length; i++) {
            System.out.print(merge[i] + " ");
        }
    }

    public static int[] merge(int[] nums1, int m, int[] nums2, int n) {
        /**
         将nums2合并到nums1中去  时间复杂度：O(m+n)
         */
        int len1 = m - 1;
        int len2 = n - 1;
        int len = m + n - 1;
        //先对num1和num2进行比较 从后往前进行遍历
        while (len1 >= 0 && len2 >= 0) {
            nums1[len--] = nums1[len1] > nums2[len2] ? nums1[len1--] : nums2[len2--];
        }
        //若len2为-1 不用不用复制了
        // 将num2剩余的len2+1个元素复制到num1中去
        System.arraycopy(nums2, 0, nums1, 0, len2 + 1);
        return nums1;
    }
}
